package jp.co.coretechno;

import java.awt.Color;
import java.awt.Graphics;

public class Cell {
	private static final int CELL_PIXEL = 16;
	private Color baseColor;
	private Color hilightColor;
	private Color shadowColor;
	private boolean isEmpty;
	
	public Cell() {
		isEmpty = true;
	}
	
	public void setCell(Color baseColor) {
		this.isEmpty = false;	
		this.baseColor = baseColor;
		
		float[] hsbvals = new float[3];
		Color.RGBtoHSB(baseColor.getRed(), baseColor.getGreen(), baseColor.getRed(), hsbvals);
		this.hilightColor = Color.getHSBColor(hsbvals[0], hsbvals[1], 0.9f);
		this.shadowColor = Color.getHSBColor(hsbvals[0], hsbvals[1], 0.6f);
	}
	
	public Color getColor() {
		return this.baseColor;
	}
	
	public void resetCell() {
		this.isEmpty = true;
	}
	
	public boolean isEmpty() {
		return this.isEmpty;
	}
	
	public void draw(Graphics g, int x, int y) {
		if (isEmpty) {
			return;
		}
		
		g.setColor(hilightColor);
		g.drawRect(x * CELL_PIXEL, y * CELL_PIXEL, CELL_PIXEL - 2, CELL_PIXEL - 2);
		
		g.setColor(shadowColor);
		g.drawRect(x * CELL_PIXEL + 1, y * CELL_PIXEL + 1, CELL_PIXEL - 2, CELL_PIXEL - 2);
		
		g.setColor(baseColor);
		g.fillRect(x * CELL_PIXEL + 1, y * CELL_PIXEL + 1, CELL_PIXEL - 2, CELL_PIXEL - 2);
	}
}
